package com.systemmanger.mapper;

import com.bean.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
//
public interface YongHuGuanLiMapper {
    @Select("<script>" +
            "select * from wms_t_user\n" +
            "\tLEFT JOIN wms_t_u_g ON wms_t_user.userID = wms_t_u_g.ugUserId\n" +
            "\tLEFT JOIN wms_t_group ON wms_t_u_g.ugGroupId = wms_t_group.groupID\n" +
            "\tLEFT JOIN wms_t_perm_group ON wms_t_group.groupID = wms_t_perm_group.groupID\n" +
            "\tLEFT JOIN wms_t_permission ON wms_t_perm_group.permID = wms_t_permission.permID  " +
            "where userIsDel = 0" +
            " <if test=\"userID !=null and userID != ''\" >" +
            "and userID =#{userID}" +
            "</if>" +
            "<if test=\" userName !=null and userName !=''\" >" +
            "and userName =#{userName}" +
            "</if>" +
            "</script>")
    public List<WmsTUser> getUserMessage(WmsTUser wmsTUser);

    /**
     * 删除该数据
     * update设置custIsDel = 0
     *
     */
    @Update("update wms_t_user set userIsDel = 1 where userID =#{userID}")
    public void deleteCustomerData(String userID);

    /**
     * 用户组查询
     * @return
     */
    @Select("SELECT * FROM wms_t_group")
    public List<WmsTGroup> sele();

    /**
     * 用户组名查询
     * @param groupName
     * @return
     */
    @Select("SELECT * FROM wms_t_permission where permID =\n" +
            "\t(SELECT permID FROM wms_t_perm_group where groupID=(\n" +
            "\t\tSELECT groupID FROM wms_t_group where  groupName=#{groupName}\n" +
            "\t\t))")
    public WmsTPermission selectPermName(@Param("groupName") String groupName);

    /**
     *
     */
    @Select("<script>" +
            "select wms_t_perm_group.groupID from wms_t_user\n" +
            "\tLEFT JOIN wms_t_u_g ON wms_t_user.userID = wms_t_u_g.ugUserId\n" +
            "\tLEFT JOIN wms_t_group ON wms_t_u_g.ugGroupId = wms_t_group.groupID\n" +
            "\tLEFT JOIN wms_t_perm_group ON wms_t_group.groupID = wms_t_perm_group.groupID" +
            " where userIsDel = 0 " +
            " <if test=\"userID !=null and userID != ''\" >" +
            "and userID =#{userID}"+
            "</if>" +
            "</script>")
    public String selectTUG(String userID);

    @Select("<script>" +
            "select wms_t_u_g.ugGroupId from wms_t_user\n" +
            "\tLEFT JOIN wms_t_u_g ON wms_t_user.userID = wms_t_u_g.ugUserId\n" +
            " where userIsDel = 0 " +
            " <if test=\"userID !=null and userID != ''\" >" +
            "and userID =#{userID}"+
            "</if>" +
            "</script>")
    public String messageTUG(String userID);

    @Update("update wms_t_user " +
            "set userName=#{userName},userAccount=#{userAccount} ,userPwd=#{userPwd}," +
            "userType=#{userType},userEditTime=#{userEditTime},userNote=#{userNote}" +
            "where userID =#{userID}")
    public void updateUser(WmsTUser wmsTUser);
}
